package com.wu;


import com.alibaba.fastjson.JSONObject;
import com.wu.utils.CommonUtils;
import lombok.extern.slf4j.Slf4j;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpSession;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.util.*;

import static com.wu.constants.Constants.ROOT_PATH;
@Slf4j
public class test {

    public static void main(String[] args) throws UnsupportedEncodingException {
        String admin = CommonUtils.encodeByMd5("admin");
        System.out.println(admin);
//        testImage();
//        String sss = "template/sss\\"+ File.separator;
//        String ss = "1234567890";
//        String s = ROOT_PATH + File.separator;
//        System.out.println(sss);
//        System.out.println(s);
        Map hashMap=new HashMap();
        hashMap.put("key2","values2");
        hashMap.put("key1","values1");

        hashMap.put("key3","values3");
        hashMap.put("key4","values4");
        hashMap.put("key5","values5");

        log.info("HashMap :{}", JSONObject.toJSONString(hashMap));

        Map map=new LinkedHashMap();
        map.put("key2","values2");
        map.put("key1","values1");

        map.put("key3","values3");
        map.put("key4","values4");
        map.put("key5","values5");

        log.info("LinkedHashMap :{}",JSONObject.toJSONString(map));

    }

    public static void test3() {
        // 根据系统的实际情况选择目录分隔符（windows下是，linux下是/）
        String separator = File.separator;
        String directory = "D:" + separator + "myDir1" + separator + "myDir2";
        // 以下这句的效果等同于上面两句，windows下正斜杠/和反斜杠都是可以的
        // linux下只认正斜杠，为了保证跨平台性，不建议使用反斜杠（在java程序中是转义字符，用\来表示反斜杠）
        // String directory = "myDir1/myDir2";
        String fileName = "myFile.txt";
        // 在内存中创建一个文件对象，注意：此时还没有在硬盘对应目录下创建实实在在的文件
        File f = new File(directory, fileName);
        if (f.exists()) {
            // 文件已经存在，输出文件的相关信息
            System.out.println(f.getAbsolutePath());
            System.out.println(f.getName());
            System.out.println(f.length());
        } else {
            // 先创建文件所在的目录
            f.getParentFile().mkdirs();
            try {
                // 创建新文件
                f.createNewFile();
            } catch (IOException e) {
                System.out.println("创建新文件时出现了错误。。。");
                e.printStackTrace();
            }
        }
    }

    public static String cast() {

        String str = "[1天,2天,3天,4天]";
        String substring = str.substring(1, str.length()-1);
        String[] strings = substring.split(",");
        StringBuilder stringBuilder = new StringBuilder();

        System.out.println("substring==>"+substring);
        System.out.println("strings=split=>"+strings);
        stringBuilder.append("[");
        for (int i = 0; i < strings.length; i++) {
            System.out.println(String.format("strings{}",i)+strings[i]);
            stringBuilder.append("\"");
            stringBuilder.append(strings[i]);
            stringBuilder.append("\"");
            if (i < strings.length - 1) {
                stringBuilder.append(",");
            }
        }
        stringBuilder.append("]");

        System.out.println("stringBuilder==>"+stringBuilder.toString());


        return null;
    }
    public static String cast2() {

        String str2 = "[{\"value\":\"阿萨德阿萨德\"},{\"value\":\"的嗷嗷的as\"}]";
        String str = "[{\"value\":\"阿萨德阿萨德\"}]";
        String substring = str.substring(1, str.length()-1);
        String[] strings = substring.split(",");

        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("[");
        for (int i = 0; i < strings.length; i++) {
            System.out.println(strings[i]);
            stringBuilder.append(strings[i].substring(9,strings[i].length()-1));
            if (i < strings.length - 1) {
                stringBuilder.append(",");
            }
        }
        stringBuilder.append("]");

        System.out.println("stringBuilder==>"+stringBuilder.toString());
        return null;
    }

    public static void testImage() {
        int[] arrys = new int[]{1, 2, 3, 4, 4};
        Arrays.fill(arrys,2,4,1);
        System.out.println(Arrays.toString(arrys));
    }

}
